/*=+--+=#=+--     Unmanned Aerial System Management Software      --+=#=+--+=#*\
|          Copyright (C) 2011 Regents of the University of Colorado.           |
|                             All Rights Reserved.                             |

     This program is free software: you can redistribute it and/or modify
     it under the terms of the GNU General Public License version 2 as
     published by the Free Software Foundation.

     This program is distributed in the hope that it will be useful,
     but WITHOUT ANY WARRANTY; without even the implied warranty of
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     GNU General Public License for more details.

     You should have received a copy of the GNU General Public License
     along with this program.  If not, see <http://www.gnu.org/licenses/>.

            Jack Elston                       Cory Dixon                        
|           elstonj@colorado.edu              dixonc@colorado.edu              |
|                                                                              |
\*=+--+=#=+--                 --+=#=+--+=#=+--                    --+=#=+--+=#*/

#ifndef __NODEICON_MANAGER_H
#define __NODEICON_MANAGER_H

#include "LayerManager.h"

/*<-------Defines--------->*/

enum NodeTypes_t {
	UNKNOWN_NODE = 0,  // unknown marker - also references main window
	GS,               // gs marker marker
	MNR,              // mnr node
	MAV,             // ares node
	SAV,             // ares node
};

enum IconTypes_t {
	UNKNOWN_t,     // unknown marker
	GS_g,          // gets circle
	MNR_g,         // gets square
	MAV_g,         // gets triangle
	SAV_g          // gets triangle
};

typedef struct _MapIcons {
	bool            track; // if track this node in window
	guint           client_ind;
	IconTypes_t     type;
	double          old_x;
	double          old_y;
	gfloat          scale;
	bool            timed_out;
	int            failure;
	int            termination;
	gboolean        draw;
	bool            filled;
	GooCanvasItem  *icon;
	GooCanvasItem  *text;
	char            text_str[128];
	char            color_str[32];
	GooCanvasItem  *item;

	_MapIcons() { icon = text = item = NULL; timed_out = false; track = false; scale = 1.0; }
	~_MapIcons() { 
		if( item ) goo_canvas_item_remove( item ); item = NULL;
		icon = NULL;
		text = NULL;
	}
} MapIcons;

/*<------End Defines------>*/

class NodeIconManager : public LayerManager
{
	private:
		bool update_gs_text(unsigned int ind);
		void create_gs_icon(unsigned int ind);
		bool update_mnr_text(unsigned int ind);
		void create_mnr_icon(unsigned int ind);
		bool update_mav_text(unsigned int ind);
		void create_mav_icon(unsigned int ind);
		bool update_sav_text(unsigned int ind);
		void create_sav_icon(unsigned int ind);

		MapIcons mapIcons[MAX_CLIENTS+1];

		bool resetFromZoom;

		int activeIconInd;
		GtkWidget      *menu;
		GtkActionGroup *action_group;          /* Packing group for our Actions */
		GtkUIManager   *menu_manager;          /* The magic widget! */

	public:
		NodeIconManager();
		~NodeIconManager();

		virtual void init(GPSMap *map = NULL);
		virtual void updateMap();
		virtual void translate_from_zoomChange(double zoom_factor);

		void addNodes();
		IconTypes_t getNodeType(int ind) { return mapIcons[ind].type; } 

		void setTrack(int ind, bool val) { mapIcons[ind].track = val; } 
		bool isTracking();
		void clearAllTrack();

		int create_control_window(GdkEventButton *event);
		static int toggle_track_cb(GtkToggleAction *action, NodeIconManager *me);
		static bool button_press_event_cb(GooCanvasItem *item, GooCanvasItem *target_item, 
		                         GdkEventButton *event, NodeIconManager *me);
};

#endif
